﻿Public Class ArgVmManager
    Private Shared mInstance As ArgVmManager
    Public Shared ReadOnly Property Instance As ArgVmManager
        Get
            If mInstance Is Nothing Then
                mInstance = New ArgVmManager
            End If
            Return mInstance
        End Get
    End Property

    Private mArgVms As Dictionary(Of ArgType, Type)
    Private mDefaultArgVmType As Type

    Private Sub New()
        mArgVms = New Dictionary(Of ArgType, Type)
        mDefaultArgVmType = GetType(StringArgVm)

        AddArgVm(Of BitArgVm)(ArgType.Bit)
        AddArgVm(Of StringArgVm)(ArgType.String)
        AddArgVm(Of ColorNumberArgVm)(ArgType.ColorNumber)
        AddArgVm(Of ListArgVm)(ArgType.List)
        AddArgVm(Of LookupArgVm)(ArgType.Lookup)
        AddArgVm(Of CharCodeArgVm)(ArgType.CharCode)
        AddArgVm(Of MaterialArgVm)(ArgType.Material)
    End Sub

    Public Sub AddArgVm(Of T As ArgumentBaseVm)(argType As ArgType)
        mArgVms.Add(argType, GetType(T))
    End Sub

    Public Function GetArgVmFor(arg As ArgumentDefinition) As ArgumentBaseVm
        Dim t As Type = Nothing
        If Not mArgVms.TryGetValue(arg.Type, t) Then
            t = mDefaultArgVmType
        End If
        Return CType(Activator.CreateInstance(t), ArgumentBaseVm)
    End Function
End Class
